# To change this template, choose Tools | Templates
# and open the template in the editor.

import unittest
from billion import Billion7404VGPM
from mockito import mock, when, verify

__author__="winstonlee"
__date__ ="$Oct 7, 2010 9:53:44 PM$"

class  Billion7404VGPMTestCase(unittest.TestCase):

    HOST = "192.168.1.254"
    USERNAME = "admin"
    PASSWORD = "password"

    RESP_PORT_A1_STATUS_CONNECTED = """ port a1 status\r\n\r\n\r\nConnected                                          = true\r\nOperationalMode                                    = G.Dmt\r\nState                                              = Showtime\r\nTxBitRate                                          = 512000\r\nRxBitRate                                          = 5088000\r\nActivateLine                                       = None\r\nWhip                                               = Disable\r\nStandard                                           = G.Dmt.BisPlusAuto\r\nImpulseTime                                        = 0\r\nadmin>\r\n"""
    EXPECT_PORT_A1_STATUS_CONNECTED = {'ActivateLine': 'None',
        'OperationalMode': 'G.Dmt',
        'Standard': 'G.Dmt.BisPlusAuto',
        'State': 'Showtime',
        'RxBitRate': '5088000',
        'TxBitRate': '512000',
        'Connected': 'true',
        'Whip': 'Disable',
        'ImpulseTime': '0'}

    RESP_SYSTEM_INFO = """ system info\r\n \r\nGlobal System Configuration:\r\n\r\n   Model Name: BiPAC 7404VGP\r\n       Vendor: Billion Electric Co., Ltd.\r\n          URL: http://www.billion.com.au\r\n\r\n  MAC address: 00:04:ED:00:00:00\r\n\r\n BootCode ver: 5.05\r\n Hardware ver: Argon 432 ADSL-M/G/VO v1.00\r\n Software ver: 5.74d\r\n   Build type: RELEASE\r\n     Compiler: gcc 2.95.3 20010315 (release)\r\n"""
    EXPECT_SYSTEM_INFO = {'Build type': 'RELEASE',
        'Vendor': 'Billion Electric Co., Ltd.',
        'MAC address': '00:04:ED:00:00:00',
        'URL': 'http://www.billion.com.au',
        'BootCode ver': '5.05',
        'Hardware ver': 'Argon 432 ADSL-M/G/VO v1.00',
        'Software ver': '5.74d',
        'Model Name': 'BiPAC 7404VGP',
        'Compiler': 'gcc 2.95.3 20010315 (release)'}

    def setUp(self):
        self.mock_telnet = mock()
        self.instance = Billion7404VGPM(Billion7404VGPMTestCase.HOST, Billion7404VGPMTestCase.USERNAME, Billion7404VGPMTestCase.PASSWORD)
        self.instance.telnet = self.mock_telnet

    def tearDown(self):
        pass

    def test_connect_bad_password(self):
        when(self.mock_telnet).expect(['Login failed', 'Login successful'], 5).thenReturn((0, None, '******\r\nLogin failed'))
        self.assertRaises(ValueError, self.instance.connect)

    def test_connect(self):
        when(self.mock_telnet).expect(['Login failed', 'Login successful'], 5).thenReturn((1, None, '*****\r\nLogin successful'))
        self.instance.connect()
        self.assertTrue(True, "This shouldn't fail")

    def test_restart(self):
        # Nothing to test since it just sends commands
        self.assertTrue(True, "This shouldn't fail")

    def test_logout(self):
        # Nothing to test since it just sends commands
        self.assertTrue(True, "This shouldn't fail")

    def test_is_wan_connected(self):
        when(self.mock_telnet).read_until(Billion7404VGPM.PROMPT_LOGGED_IN, 15).thenReturn(Billion7404VGPMTestCase.RESP_PORT_A1_STATUS_CONNECTED)
        self.assertEquals("true", self.instance.is_wan_connected(), "port a1 status parser is broken")

    def test_get_system_info(self):
        when(self.mock_telnet).read_until(Billion7404VGPM.PROMPT_LOGGED_IN, 15).thenReturn(Billion7404VGPMTestCase.RESP_SYSTEM_INFO)
        self.assertEquals(Billion7404VGPMTestCase.EXPECT_SYSTEM_INFO, self.instance.get_system_info(), "system info parser is broken")

    def test_connect_wan(self):
        # Nothing to test since it just sends commands
        self.assertTrue(True, "This shouldn't fail")

if __name__ == '__main__':
    unittest.main()

